import math

def distance_on_unit_sphere(lat1, long1, lat2, long2):

  # Convert latitude and longitude to 
  # spherical coordinates in radians.
  degrees_to_radians = math.pi/180.0
        
  # phi = 90 - latitude
  phi1 = (90.0 - lat1)*degrees_to_radians
  phi2 = (90.0 - lat2)*degrees_to_radians
        
  # theta = longitude
  theta1 = long1*degrees_to_radians
  theta2 = long2*degrees_to_radians
        
  # Compute spherical distance from spherical coordinates.
        
  # For two locations in spherical coordinates 
  # (1, theta, phi) and (1, theta, phi)
  # cosine( arc length ) = 
  #    sin phi sin phi' cos(theta-theta') + cos phi cos phi'
  # distance = rho * arc length
    
  cos = (math.sin(phi1)*math.sin(phi2)*math.cos(theta1 - theta2) + 
         math.cos(phi1)*math.cos(phi2))
  arc = math.acos( cos )

  # Remember to multiply arc by the radius of the earth 
  # in your favorite set of units to get length.
  return 6371 * arc

def quicksort (lista,lista2) : 
  """Ordena la lista siguiendo el algoritmo quicksort 
  o de ordenacion rapida""" 
  listas = ordena_quicksort(lista,lista2,0,len(lista)-1) 
  
  return listas
 
def ordena_quicksort (lista,lista2,izdo,dcho) : 
  if izdo<dcho : 
    pivote=lista[(izdo+dcho)/2] 
    i,d=izdo,dcho 
    while i<=d : 
      while lista[i]<pivote : i+=1 
      while lista[d]>pivote : d-=1 
      if i<=d : 
        lista[i],lista[d]=lista[d],lista[i]
        lista2[i],lista2[d]=lista2[d],lista2[i]
        i+=1 
        d-=1 
    if izdo<d : ordena_quicksort(lista,lista2,izdo,d) 
    if i<dcho : ordena_quicksort(lista,lista2,i,dcho)
  listas = [0,1]
  listas[0] = lista
  listas[1] = lista2
  return listas  
